﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WWNotice.constant;
using WWNotice.Utils;

namespace WWNotice.service
{
    public class Notice
    {
        static string errMessage = "";

        public static void getWindows()
        {
            Process[] process = Process.GetProcesses();
            List<string> b = new List<string>();
            foreach (Process p in process)
            {
                string text = p.MainWindowTitle.ToString();
                if (text.Contains("系统消息"))
                {
                    string user = text.Substring(0, text.Length - 6);
                    WechatMessageVo wechatMessageVo = new WechatMessageVo();
                    wechatMessageVo.toUserList.Remove("WangYongMing");
                    wechatMessageVo.toUserList.Add("ZhuGuangPing");
                    wechatMessageVo.toUserList.Add("CaoZhen");
                    wechatMessageVo.bugAgentId = AgentEnum.wangwang.ToString();
                    wechatMessageVo.content = "旺旺来人了";
                    HttpUtil.PostJsonRequest(JsonConvert.SerializeObject(wechatMessageVo), HttpServiceApi.WECHAT_NOTICE_URL);

                }
                if (!string.IsNullOrEmpty(text)) b.Add(text);
            }
        }

        /// <summary>
        /// 错误消息发送
        /// </summary>
        /// <param name="message"></param>
        public static void errorMessage(string message)
        {
            if (errMessage.Equals(message))
            {
                return;
            }
            WechatMessageVo wechatMessageVo = new WechatMessageVo();
            wechatMessageVo.bugAgentId = AgentEnum.bug.ToString();
            wechatMessageVo.content = message;
            string result = HttpUtil.PostJsonRequest(JsonConvert.SerializeObject(wechatMessageVo), HttpServiceApi.WECHAT_NOTICE_URL);
            errMessage = message;
        }
    }

    /// <summary>
    /// 微信推送消息实体
    /// </summary>
    public class WechatMessageVo
    {
        public WechatMessageVo()
        {
            this.toUserList = new List<string>();

            this.toUserList.Add("ShaJun");
            this.toUserList.Add("WangYongMing");
            this.toUserList.Add("ShaJie");

        }
        /**
         * 消息接收人
         */
        public List<String> toUserList;

        /**
         * 应用id
         */
        public String bugAgentId;

        /**
         * 消息类容
         */
        public String content;


    }

    /// <summary>
    /// 应用枚举
    /// </summary>
    public enum AgentEnum
    {
        wangwang = 1000002,
        bug = 1000003,
        hxw = 1000005
    }


}
